/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 * Source.java
 *
 * Created on 23.11.2009, 18:10:34
 */
package GUI.iFrames.DataSourceComponents;

import input.ExcelTools;
import input.HEATMAP_BUFFER_IO;
import input.IoToolbox;
import input.JxlExporter;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;

import javax.swing.BoxLayout;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

import org.jfree.data.statistics.Statistics;
import org.jfree.data.xy.DefaultXYZDataset;

import toolz.ColorColumnRenderer;
import toolz.HeatTableCellRenderer;
import toolz.IMS_CSV_File;
import toolz.ImageMethods;
import toolz.JTableCustomizer;
import toolz.Misc;
import toolz.StaticExchange;
import toolz.netCdfTools;
import DATA.BbImsSet;
import DATA.iDataSet;
import DATA.iDataSetParts.IdInfo;
import DATA.iDataSetParts.Measurement;
import DATA.iDataSetParts.Peaklist;
import DATA.iDataSetParts.SubstanceInfo;
import GUI.BaseFrame;
import GUI.WaitJDialog;
import GUI.WaitJDialogModal;
import GUI.iFrames.AlignInternalFrame;
import GUI.iFrames.AlignK0InternalFrame;
import GUI.iFrames.ChartExportOptionsInternalFrame;
import GUI.iFrames.ChartInternalFrame;
import GUI.iFrames.CorrelationBubblePlot;
import GUI.iFrames.GeneralTabInternalFrame;
import GUI.iFrames.PcaInternalFrame;
import GUI.iFrames.WallpaperInternalFrame;
import GUI.iFrames.infoLabelInternalFrame;
import GUI.iFrames.HetmapFrameComponents.HeatmapInternalFrame;
import javax.swing.JButton;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.GroupLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * 
 * @author Bunkowski
 */
public class DataSourcesInternalFrame extends javax.swing.JInternalFrame implements DropTargetListener {

	public static final long serialVersionUID = 1L;

	public DropTarget dropTarget = new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, this, true, null);
	public iDataSet idataset;
	public JTable table = new JTable();
	private int column; // tableselectionmagic
	public HeatmapInternalFrame heatmapInternalFrame;
	public int selectedLabel = -1, selectedClasses = -1;
	private TableCellRenderer tcr;

	private JScrollPane tableScrollpane;

	private JCheckBoxMenuItem showK0ShiftCheckBox;

	// empty constructor for netbeans guibuilder
	public DataSourcesInternalFrame() {
		initComponents();
	}

	public DataSourcesInternalFrame(iDataSet idataset) {
		initComponents();
		init(idataset);
	}

	public DataSourcesInternalFrame(Vector<Measurement> measurements) {
		initComponents();
		idataset = new iDataSet(measurements);
		idataset.name = new File(measurements.get(0).path).getParentFile().getName();
		init(idataset);
	}

	public DataSourcesInternalFrame(BbImsSet bbimsset) {
		initComponents();
		idataset = new iDataSet(bbimsset.measurements);
		idataset.name = bbimsset.name;
		if (bbimsset.infos.size() > 0) {
			idataset.addMeasurementIdInfos(bbimsset.infos, new String[] { "class" });
		}
		init(idataset);
	}

	private void init(iDataSet idataset) {
		this.idataset = idataset;
		syncCheckboxes();

		// projectNameLabel.setText(idataset.name);
		table.setModel(new DefaultTableModel(idataset.getData(), idataset.getHeader()));
		table.setDragEnabled(true);
		tableScrollpane = new JScrollPane(table);
		JTableCustomizer.changeComperatorToDoubleIfPossible(table);
		center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
		center.add(tableScrollpane);
		// trashLabel.table = table;
		table.setColumnSelectionAllowed(true);

		// magic to allow tablecolumn selection by rightklick on header
		table.getTableHeader().addMouseListener(new MouseAdapter() {

			public void mouseReleased(MouseEvent e) {
				if (e.getButton() == 3) {
					column = table.getTableHeader().columnAtPoint(e.getPoint());
					table.setRowSelectionAllowed(false);
					table.setColumnSelectionInterval(column, column);
				}
			}
		});

		table.addMouseListener(new MouseAdapter() {

			public void mousePressed(MouseEvent e) {
				if (table.getSelectedColumn() != column) {
					table.setRowSelectionAllowed(true);
				}
			}

			public void mouseReleased(MouseEvent e) {
				showHeatmap();
			}

			public void mouseClicked(MouseEvent e) {
			}
		});
		// tablemagic end

		updateLabel();

		table.addKeyListener(new KeyAdapter() {

			public void keyReleased(KeyEvent e) {
				showHeatmap();
			}
		});

		tcr = table.getColumnModel().getColumn(0).getCellRenderer();
		JTableCustomizer.fitAllColumnWidth(table);
		setTitle("Data source    " + table.getRowCount() + " elements");
	}

	private void syncCheckboxes() {
		idataset.showPeakIntensities = showMaxIntensityCheckBox.isSelected();
		idataset.showPeakVolume = showVolumeCheckBox.isSelected();
		idataset.showRT = showRTCheckBox.isSelected();
		idataset.showDT = showDTCheckBox.isSelected();
	}

	private Measurement getSelectedMeas() {
		// int selectedLine = table.getRowSorter().convertRowIndexToModel(table.getSelectedRow());
		Measurement selectedMeas = null;
		String value = (String) table.getValueAt(table.getSelectedRow(), 1);
		for (int i = 0; i < idataset.measurements.size(); i++) {
			if (idataset.measurements.get(i).measurementID.equals(value)) {
				selectedMeas = idataset.measurements.get(i);
			}
		}
		return selectedMeas;
	}

	private Vector<Measurement> getSelectedMeasurements() {
		Vector<Measurement> selectedMeas = new Vector<Measurement>();
		for (int i = 0; i < table.getSelectedRows().length; i++) {
			String value = (String) table.getValueAt(table.getSelectedRows()[i], 1);
			for (int j = 0; j < idataset.measurements.size(); j++) {
				if (idataset.measurements.get(j).measurementID.equals(value)) {
					selectedMeas.add(idataset.measurements.get(j));
				}
			}
		}
		return selectedMeas;
	}

	public SubstanceInfo getSelectedSubstance() {
		SubstanceInfo s = new SubstanceInfo(new String[] { "", "1", "1", "1", "1" });
		try {
			int colum = table.getSelectedColumn();
			String name = idataset.getHeader().get(colum);
			for (SubstanceInfo si : idataset.substanceInfos) {
				if (si.name.equals(name)) {
					s = si;
				}
			}
		} catch (Exception x) {
			System.out.println("no column selected");
		}
		return s;
	}

	public SubstanceInfo getSubstanceAt(int colum) {
		int infoShift = 0;// idataset.infoShift;
		System.out.print("getSubstanceAt: " + colum);
		String columnIsNoSubstance = table.getTableHeader().getColumnModel().getColumn(colum + infoShift)
				.getHeaderValue().toString();
		SubstanceInfo s = new SubstanceInfo(new String[] { columnIsNoSubstance, "1", "1", "1", "1" });
		try {
			String name = idataset.getHeader().get(colum);
			for (SubstanceInfo si : idataset.substanceInfos) {
				if (si.name.equals(name)) {
					s = si;
				}
			}
		} catch (Exception x) {
			System.out.println("no column selected");
		}
		System.out.println(" " + s.name);
		return s;
	}

	public Vector<String> getMeasurementIds() {
		int measurementIdsIndex = 1;
		Vector<String> measurementIds = new Vector<String>();
		for (int i = 0; i < table.getRowCount(); i++) {
			String value = (String) table.getValueAt(i, measurementIdsIndex);
			measurementIds.add(value);
		}
		return measurementIds;
	}

	public void showHeatmap() {
		if (showHeatmapButton.isSelected()) {

			final DataSourcesInternalFrame parent = this;

			final WaitJDialogModal wait = new WaitJDialogModal("Heatmap generator", parent);
			Runnable runnable = new Runnable() {

				public void run() {
					if (showHeatmapButton.isSelected() && table.getSelectedRow() != -1) {
						if (heatmapInternalFrame == null) {
							wait.step("Initializing heatmapexplorer");
							heatmapInternalFrame = new HeatmapInternalFrame(parent, new Point(parent.getX() + 50,
									parent.getY() + 80));
							heatmapInternalFrame.showHeatmap(getSelectedMeas());
							BaseFrame.applyFrame(heatmapInternalFrame);
							heatmapInternalFrame.moveToFront();
						} else {
							wait.step("Loading " + getSelectedMeas());
							heatmapInternalFrame.showHeatmap(getSelectedMeas());
						}
						heatmapInternalFrame.setSelectedMeasurement(getSelectedMeas());

					} else {
						closeHeatmap();
					}
					// Waitdialog end step
					wait.dispose();
				}
			};
			Thread thread = new Thread(runnable);
			wait.setThread(thread);

			thread.start();
		}
	}

	// private void showDetails() {
	// if (showDetailsButton.isSelected()) {
	// if (detailsInternalFrame == null) {
	// detailsInternalFrame = new MeasDetails();
	// } else {
	// }
	// }
	// }
	public void closeHeatmap() {
		if (heatmapInternalFrame != null) {
			// BaseFrame.removeFrame(heatmapInternalFrame);
			heatmapInternalFrame.dispose();
		}

		showHeatmapButton.setSelected(false);
		heatmapInternalFrame = null;
	}

	public void updateTableWithoutHeatmap() {

		// show substance infos in 3 rows to reduce x-axis dimension in table
		Vector<String> transformedHeader = new Vector<String>();
		boolean twoLineHeader = false;
		for (String s : idataset.getHeader()) {
			String transformedString = s;
			// if (s.contains("Area (") && s.contains("-") && s.contains(")")) {
			// transformedString = s.replace("Area (", "<HTML>").replace("-", "-<br>").replace(")", "</HTML>");
			// twoLineHeader = true;
			// }
			transformedHeader.add(transformedString);
		}

		if (twoLineHeader) {
			int height = 36;
			int width = tableScrollpane.getColumnHeader().getWidth();
			tableScrollpane.getColumnHeader().setPreferredSize(new Dimension(width, height));
		}

		List sort = table.getRowSorter().getSortKeys();
		table.setModel(new DefaultTableModel(idataset.getData(), transformedHeader));
		JTableCustomizer.changeComperatorToDoubleIfPossible(table);
		table.getRowSorter().setSortKeys(sort);

		if (selectedClasses != -1) {
			ColorColumnRenderer ccr = new ColorColumnRenderer(new Color(255, 200, 200));
			table.getColumnModel().getColumn(selectedClasses).setCellRenderer(ccr);
		}
		if (selectedLabel != -1) {
			ColorColumnRenderer ccr = new ColorColumnRenderer(new Color(200, 200, 255));
			table.getColumnModel().getColumn(selectedLabel).setCellRenderer(ccr);
		}
		updateLabel();
		JTableCustomizer.fitAllColumnWidth(table);
		crashsave();
		setTitle("Data source    " + table.getRowCount() + " elements");

		if (heatCellsMenuItem.isSelected()) {
			for (int i = idataset.infoShift + idataset.numberOfMeasurementInfos; i < table.getColumnCount(); i++) {
				table.getColumnModel().getColumn(i).setCellRenderer(new HeatTableCellRenderer());
			}
		} else {
			for (int i = idataset.infoShift + idataset.numberOfMeasurementInfos; i < table.getColumnCount(); i++) {
				table.getColumnModel().getColumn(i).setCellRenderer(new DefaultTableCellRenderer());
			}
		}
		if (heatmapInternalFrame != null) {
			heatmapInternalFrame.showSubstanceInfos();
		}
	}

	public void updateTable() {
		updateTableWithoutHeatmap();
		if (heatmapInternalFrame != null) {
			heatmapInternalFrame.updateHeatmap();
		}
	}

	private void crashsave() {
		ObjectOutputStream oo = null;
		try {

			oo = new ObjectOutputStream(new FileOutputStream("crashsave.ido"));
			oo.writeObject(idataset);
			oo.close();
		} catch (Exception ex) {
			try {
				oo.close();
			} catch (IOException ex1) {
				System.out.println("Error, can not close damaged object out stream");
			}
			ex.printStackTrace();
			System.out.println("Error writing crashfile");
		}
	}

	private void ido_historySave() {

		ObjectOutputStream oo = null;
		try {
			oo = new ObjectOutputStream(new FileOutputStream("undofile.undo"));
			oo.writeObject(idataset);
			oo.close();
		} catch (Exception ex) {
			try {
				oo.close();
			} catch (IOException ex1) {
				System.out.println("Error, can not close damaged object out stream");
			}
			ex.printStackTrace();
			System.out.println("Error writing undo");
		}
	}

	private void addInformationFromDrop(final String s) {
		ido_historySave();
		// Waitdialog start code
		final Component parent = this;

		final WaitJDialogModal wait = new WaitJDialogModal("Adding drop information ...", parent);
		Runnable runnable = new Runnable() {

			public void run() {
				boolean abort = false;
				Vector<File> filesToOpen = IoToolbox.decodeTabbedFileString(s);

				// if its an xls file it can be either idinfo or measurement info
				if (filesToOpen.get(0).toString().endsWith(".xls") && !filesToOpen.get(0).toString().contains("IMSSet")) {

					// boolean allAreIDs = true;
					boolean allAreMeasurements = true;

					Vector<IdInfo> idInfos = new Vector<IdInfo>();
					Vector<String[]> idinfotable = ExcelTools.importXLS(filesToOpen.get(0), 0);

					String[] readHeader = idinfotable.elementAt(0);
					String[] infoHeader = new String[readHeader.length - 1];
					for (int i = 1; i < readHeader.length; i++) {
						System.out.println("header " + i + " =" + readHeader[i]);
						infoHeader[i - 1] = readHeader[i];
						abort = wait.step("processing drop");
						if (abort) {
							break;
						}
					}
					for (int i = 1; i < idinfotable.size(); i++) { // skipping 0 line header
						String[] readline = idinfotable.elementAt(i);
						Vector<String> infos = new Vector<String>();

						for (int j = 1; j < readline.length; j++) {
							infos.add(readline[j]);
						}

						if (!readline[0].contains("_")) {
							allAreMeasurements = false;
						}

						if (readline[0].contains("_")) {
							idInfos.add(new IdInfo(readline[0].split("_")[1], infos));
						} else {
							idInfos.add(new IdInfo(readline[0], infos));
						}
						abort = wait.step("processing drop");
						if (abort) {
							break;
						}

					}
					if (allAreMeasurements) {
						System.out.println("Measurement Info Drop detected");
						idataset.addMeasurementIdInfos(idInfos, infoHeader);
					}

					updateTable();
				} else if (filesToOpen.get(0).toString().endsWith(".pl")) {
					System.out.println("PeaklistDrop registred");
					Vector<Peaklist> peaklists = new Vector<Peaklist>();
					for (File f : filesToOpen) {
						peaklists.add(new Peaklist(f));
						abort = wait.step("processing drop");
						if (abort) {
							break;
						}
					}

					idataset.addPeakLists(peaklists);

					updateTable();
				} else // if the files start with a measurement
				if (filesToOpen.get(0).toString().endsWith("ims.csv")) {

					System.out.println("Measurement add drop detected");

					Vector<Measurement> m = new Vector<Measurement>();
					for (File f : filesToOpen) {
						if (f.toString().endsWith("ims.csv")) {
							m.add(new Measurement(f.toString()));
						}
						abort = wait.step("processing drop");
						if (abort) {
							break;
						}
					}
					idataset.addMeasurements(m);

					updateTable();
				} else if (filesToOpen.get(0).toString().endsWith(".CDF")) {
					System.out.println("MS drop detected");
					Vector<Vector> gcmsFiles = new Vector<Vector>();
					for (File f : filesToOpen) {
						if (f.toString().endsWith(".CDF")) {
							gcmsFiles.add(netCdfTools.readFile(f.getPath()));
						}
						abort = wait.step("Reading " + f.getName());
						if (abort) {
							break;
						}

					}
					idataset.addGcmsFiles(gcmsFiles);
					updateTable();
				} else if (!filesToOpen.get(0).toString().endsWith(".xls")
						&& !filesToOpen.get(0).toString().endsWith(".pl")) {
					System.out.println("SubstanceInfoDrop registred");
					Vector<SubstanceInfo> substanceinfo = IoToolbox.decodeSubstanceInfos(s);
					idataset.addSubstanceInfos(substanceinfo);

					updateTable();
				}

				// Waitdialog end step
				wait.dispose();
			}
		};
		Thread thread = new Thread(runnable);
		wait.setThread(thread);
		thread.start();
	}

	private void updateLabel() {
		if (idataset.measurements != null) {
			if (idataset.measurements.size() > 0) {
				dataLabel.setBackground(Color.green);
			} else {
				dataLabel.setBackground(Color.red);
			}
		}

		if (idataset.idInfos.size() + idataset.measurementInfos.size() > 0) {
			metaInfoLabel.setBackground(Color.green);
		} else {
			metaInfoLabel.setBackground(Color.lightGray);
		}

		if (idataset.substanceInfos != null) {
			if (idataset.substanceInfos.size() > 0) {
				areasLabel.setBackground(Color.green);
			} else {
				areasLabel.setBackground(Color.lightGray);
			}
		}

		if (idataset.peaklists != null) {
			if (idataset.peaklists.size() > 0) {
				peakLabel.setBackground(Color.green);
			} else {
				peakLabel.setBackground(Color.lightGray);
			}
		}
	}

	/**
	 * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
	 * content of this method is always regenerated by the Form Editor.
	 */
	private void initComponents() {

		dataPopup = new javax.swing.JPopupMenu();
		showSampleTypeCheckBox = new javax.swing.JCheckBoxMenuItem();
		showCommentCheckBox = new javax.swing.JCheckBoxMenuItem();
		showFilenameCheckBox = new javax.swing.JCheckBoxMenuItem();
		jSeparator6 = new javax.swing.JSeparator();
		copyFilesMenuItem = new javax.swing.JMenuItem();
		jSeparator1 = new javax.swing.JSeparator();
		deleteDataItem = new javax.swing.JMenuItem();
		peakPopup = new javax.swing.JPopupMenu();
		showMaxIntensityCheckBox = new javax.swing.JCheckBoxMenuItem();
		showVolumeCheckBox = new javax.swing.JCheckBoxMenuItem();
		showRTCheckBox = new javax.swing.JCheckBoxMenuItem();
		showDTCheckBox = new javax.swing.JCheckBoxMenuItem();
		showAlignmentFactorCheckBox = new javax.swing.JCheckBoxMenuItem();
		showK0ShiftCheckBox = new javax.swing.JCheckBoxMenuItem();
		jSeparator4 = new javax.swing.JSeparator();
		exportSelectedPeaklists = new javax.swing.JMenuItem();
		deleteSelectedPeaklists = new javax.swing.JMenuItem();
		findPeaksMenu = new javax.swing.JMenu();
		detectPeaksFineMenuItem = new javax.swing.JMenuItem();
		detectPeaksCoarseMenuItem = new javax.swing.JMenuItem();
		metaInfoPopup = new javax.swing.JPopupMenu();
		addInfoMenuItem = new javax.swing.JMenuItem();
		addToNewMenuItem = new javax.swing.JMenuItem();
		multiplyToNewMenuItem = new javax.swing.JMenuItem();
		jSeparator5 = new javax.swing.JSeparator();
		deleteSelectedInformation = new javax.swing.JMenuItem();
		clearInformationTable = new javax.swing.JMenuItem();
		areasPopup = new javax.swing.JPopupMenu();
		editAreasMenuItem = new javax.swing.JMenuItem();
		copyAreasMenuItem = new javax.swing.JMenuItem();
		deleteAreasMenuItem = new javax.swing.JMenuItem();
		generatorPopup = new javax.swing.JPopupMenu();
		chartFromColumnMenuItem = new javax.swing.JMenuItem();
		saveChartsMenuItem = new javax.swing.JMenuItem();
		WallpaperMenuItem = new javax.swing.JMenuItem();
		correlationAVAMenuItem = new javax.swing.JMenuItem();
		pca = new javax.swing.JMenuItem();
		heatCellsMenuItem = new javax.swing.JCheckBoxMenuItem();
		useRl = new javax.swing.JMenuItem();
		javax.swing.JPanel topPanel = new javax.swing.JPanel();
		dataLabel = new javax.swing.JLabel();
		metaInfoLabel = new javax.swing.JLabel();
		areasLabel = new javax.swing.JLabel();
		peakLabel = new javax.swing.JLabel();
		javax.swing.JButton classesButton = new javax.swing.JButton();
		javax.swing.JButton labelButton = new javax.swing.JButton();
		javax.swing.JButton undoButton = new javax.swing.JButton();
		center = new javax.swing.JPanel();
		javax.swing.JButton cacheImagesButton = new javax.swing.JButton();
		javax.swing.JButton alignButton = new javax.swing.JButton();
		showHeatmapButton = new javax.swing.JToggleButton();
		javax.swing.JButton saveAllButton = new javax.swing.JButton();
		javax.swing.JButton exportXls = new javax.swing.JButton();
		chartGeneratorLabel = new javax.swing.JLabel();

		showSampleTypeCheckBox.setText("show sample type");
		showSampleTypeCheckBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				showSampleTypeCheckBoxActionPerformed(evt);
			}
		});
		dataPopup.add(showSampleTypeCheckBox);

		showAlignmentFactorCheckBox.setText("show alignment factor");
		showAlignmentFactorCheckBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				idataset.showAlignmentFactor = showAlignmentFactorCheckBox.isSelected();
				updateTable();
			}
		});
		dataPopup.add(showAlignmentFactorCheckBox);

		showK0ShiftCheckBox.setText("show k0 shift");
		showK0ShiftCheckBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				idataset.showK0Shift = showK0ShiftCheckBox.isSelected();
				updateTable();
			}
		});
		dataPopup.add(showK0ShiftCheckBox);

		showCommentCheckBox.setText("show comment");
		showCommentCheckBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				idataset.showCommentInformation = showCommentCheckBox.isSelected();
				updateTable();
			}
		});
		dataPopup.add(showCommentCheckBox);

		showFilenameCheckBox.setText("show filename");
		showFilenameCheckBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				idataset.showFilename = showFilenameCheckBox.isSelected();
				updateTable();
			}
		});
		dataPopup.add(showFilenameCheckBox);
		dataPopup.add(jSeparator6);

		copyFilesMenuItem.setText("copy files to iphex dir");
		copyFilesMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				copyFilesMenuItemActionPerformed(evt);
			}
		});
		dataPopup.add(copyFilesMenuItem);
		dataPopup.add(jSeparator1);

		deleteDataItem.setFont(new java.awt.Font("Tahoma", 1, 15));
		deleteDataItem.setForeground(new java.awt.Color(255, 0, 0));
		deleteDataItem.setText("delete selected");
		deleteDataItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				ido_historySave();
				Vector<Measurement> selectedMeas = getSelectedMeasurements();
				for (Measurement m : selectedMeas) {
					idataset.measurements.remove(m);
				}
				updateTable();
			}
		});
		dataPopup.add(deleteDataItem);

		showMaxIntensityCheckBox.setSelected(true);
		showMaxIntensityCheckBox.setText("show max intensity");
		showMaxIntensityCheckBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				syncCheckboxes();
				updateTable();
			}
		});
		peakPopup.add(showMaxIntensityCheckBox);

		showVolumeCheckBox.setText("show volume");
		showVolumeCheckBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				syncCheckboxes();
				updateTable();
			}
		});
		peakPopup.add(showVolumeCheckBox);

		showRTCheckBox.setText("show RT");
		showRTCheckBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				syncCheckboxes();
				updateTable();
			}
		});
		peakPopup.add(showRTCheckBox);

		showDTCheckBox.setText("show 1/k0");
		showDTCheckBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				syncCheckboxes();
				updateTable();
			}
		});
		peakPopup.add(showDTCheckBox);
		peakPopup.add(jSeparator4);

		exportSelectedPeaklists.setText("save selected");
		exportSelectedPeaklists.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				exportSelectedPeaklistsActionPerformed(evt);
			}
		});
		peakPopup.add(exportSelectedPeaklists);

		deleteSelectedPeaklists.setFont(new java.awt.Font("Tahoma", 1, 15));
		deleteSelectedPeaklists.setForeground(new java.awt.Color(255, 0, 0));
		deleteSelectedPeaklists.setText("delete selected");
		deleteSelectedPeaklists.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				deleteSelectedPeaklistsActionPerformed(evt);
			}
		});
		peakPopup.add(deleteSelectedPeaklists);

		findPeaksMenu.setText("generate for selection");

		detectPeaksFineMenuItem.setText("fine");
		detectPeaksFineMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				findPeaks(false);
			}
		});
		findPeaksMenu.add(detectPeaksFineMenuItem);

		detectPeaksCoarseMenuItem.setText("coarse");
		detectPeaksCoarseMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				findPeaks(true);
			}
		});
		findPeaksMenu.add(detectPeaksCoarseMenuItem);

		peakPopup.add(findPeaksMenu);

		addInfoMenuItem.setText("add/edit info for selection");
		addInfoMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				addInfoMenuItemActionPerformed(evt);
			}
		});
		metaInfoPopup.add(addInfoMenuItem);

		addToNewMenuItem.setText("add selection");
		addToNewMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				addToNewMenuItemActionPerformed(evt);
			}
		});
		metaInfoPopup.add(addToNewMenuItem);

		multiplyToNewMenuItem.setText("multiply selection");
		multiplyToNewMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				multiplyToNewMenuItemActionPerformed(evt);
			}
		});
		metaInfoPopup.add(multiplyToNewMenuItem);
		metaInfoPopup.add(jSeparator5);

		deleteSelectedInformation.setFont(new java.awt.Font("Tahoma", 1, 15));
		deleteSelectedInformation.setForeground(new java.awt.Color(255, 0, 0));
		deleteSelectedInformation.setText("delete selected info columns");
		deleteSelectedInformation.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				deleteSelectedInformationActionPerformed(evt);
			}
		});
		metaInfoPopup.add(deleteSelectedInformation);

		clearInformationTable.setFont(new java.awt.Font("Tahoma", 1, 15));
		clearInformationTable.setForeground(new java.awt.Color(255, 0, 0));
		clearInformationTable.setText("delete all");
		clearInformationTable.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				ido_historySave();
				idataset.clearInfotables();
				updateTable();
			}
		});
		metaInfoPopup.add(clearInformationTable);

		editAreasMenuItem.setText("edit areas");
		editAreasMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				editAreasMenuItemActionPerformed(evt);
			}
		});
		areasPopup.add(editAreasMenuItem);

		copyAreasMenuItem.setText("copy areas");
		copyAreasMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				copyAreasMenuItemActionPerformed(evt);
			}
		});
		areasPopup.add(copyAreasMenuItem);

		deleteAreasMenuItem.setFont(new java.awt.Font("Tahoma", 1, 15));
		deleteAreasMenuItem.setForeground(new java.awt.Color(255, 0, 0));
		deleteAreasMenuItem.setText("delete all");
		deleteAreasMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				deleteAreasMenuItemActionPerformed(evt);
			}
		});
		areasPopup.add(deleteAreasMenuItem);

		chartFromColumnMenuItem.setText("Show charts for selected columns");
		chartFromColumnMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				chartFromColumnMenuItemActionPerformed(evt);
			}
		});
		generatorPopup.add(chartFromColumnMenuItem);

		saveChartsMenuItem.setText("Save selected columns as charts");
		saveChartsMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				saveChartsMenuItemActionPerformed(evt);
			}
		});
		generatorPopup.add(saveChartsMenuItem);

		WallpaperMenuItem.setText("Wallpaper (Selection)");
		WallpaperMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				WallpaperMenuItemActionPerformed(evt);
			}
		});
		generatorPopup.add(WallpaperMenuItem);

		correlationAVAMenuItem.setText("Correlation analysis (all vs. all)");
		correlationAVAMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				correlationAVAMenuItemActionPerformed(evt);
			}
		});
		generatorPopup.add(correlationAVAMenuItem);

		pca.setText("PCA (Selected)");
		pca.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				pcaActionPerformed(evt);
			}
		});
		generatorPopup.add(pca);

		heatCellsMenuItem.setText("Heat cells");
		heatCellsMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				heatCellsMenuItemActionPerformed(evt);
			}
		});
		generatorPopup.add(heatCellsMenuItem);

		useRl.setText("subtract selection as reference");
		useRl.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				useRlActionPerformed(evt);
			}
		});
		generatorPopup.add(useRl);

		setClosable(true);
		setIconifiable(true);
		setMaximizable(true);
		setResizable(true);
		setTitle("Data Source");
		addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() {
			public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
				formInternalFrameClosing(evt);
			}
		});

		dataLabel.setText("MCC/IMS Data");
		dataLabel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
		dataLabel.setOpaque(true);
		// dataLabel.add(getShowAlignmentFactor());
		// dataLabel.add(getShowAlignmentFactor());
		dataLabel.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				JLabel temp = dataLabel;
				dataPopup.show(temp, 0, temp.getHeight());
			}
		});

		metaInfoLabel.setText("Meta info");
		metaInfoLabel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
		metaInfoLabel.setOpaque(true);
		metaInfoLabel.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				JLabel temp = metaInfoLabel;
				metaInfoPopup.show(temp, 0, temp.getHeight());
			}
		});

		areasLabel.setText("Areas");
		areasLabel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
		areasLabel.setOpaque(true);
		areasLabel.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				JLabel temp = areasLabel;
				areasPopup.show(temp, 0, temp.getHeight());
			}
		});

		peakLabel.setText("Peak data");
		peakLabel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
		peakLabel.setOpaque(true);
		peakLabel.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				JLabel temp = peakLabel;
				peakPopup.show(temp, 0, temp.getHeight());
			}
		});

		classesButton.setText("set as class");
		classesButton.setMargin(new java.awt.Insets(0, 3, 0, 3));
		classesButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				classesButtonActionPerformed(evt);
			}
		});

		labelButton.setText("set as label");
		labelButton.setMargin(new java.awt.Insets(0, 3, 0, 3));
		labelButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				labelButtonActionPerformed(evt);
			}
		});

		undoButton.setText("<- undo");
		undoButton.setMargin(new java.awt.Insets(0, 3, 0, 3));
		undoButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				undoButtonActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout gl_topPanel = new javax.swing.GroupLayout(topPanel);
		topPanel.setLayout(gl_topPanel);
		gl_topPanel.setHorizontalGroup(gl_topPanel.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						gl_topPanel
								.createSequentialGroup()
								.addContainerGap()
								.addComponent(labelButton)
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(classesButton)
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 94,
										Short.MAX_VALUE).addComponent(undoButton)
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(dataLabel)
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(metaInfoLabel)
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(areasLabel)
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(peakLabel).addContainerGap()));
		gl_topPanel.setVerticalGroup(gl_topPanel.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						gl_topPanel.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(labelButton).addComponent(classesButton).addComponent(peakLabel)
								.addComponent(areasLabel).addComponent(metaInfoLabel).addComponent(dataLabel)
								.addComponent(undoButton)));

		center.setBackground(new java.awt.Color(255, 255, 255));

		javax.swing.GroupLayout gl_center = new javax.swing.GroupLayout(center);
		center.setLayout(gl_center);
		gl_center.setHorizontalGroup(gl_center.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 528, Short.MAX_VALUE));
		gl_center.setVerticalGroup(gl_center.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 250, Short.MAX_VALUE));

		cacheImagesButton.setText("Cache data");
		cacheImagesButton.setMargin(new java.awt.Insets(2, 5, 2, 5));
		cacheImagesButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				cacheImagesButtonActionPerformed(evt);
			}
		});

		alignButton.setText("Align RT");
		alignButton.setMargin(new java.awt.Insets(2, 5, 2, 5));
		alignButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				alignButtonActionPerformed(evt);
			}
		});

		showHeatmapButton.setFont(new java.awt.Font("Tahoma", 1, 14));
		showHeatmapButton.setText("Show Heatmap");
		showHeatmapButton.setMargin(new java.awt.Insets(2, 5, 2, 5));
		showHeatmapButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				showHeatmapButtonActionPerformed(evt);
			}
		});

		saveAllButton.setText("Save .ido");
		saveAllButton.setMargin(new java.awt.Insets(2, 5, 2, 5));
		saveAllButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				saveAllButtonActionPerformed(evt);
			}
		});

		exportXls.setText("Export .xls");
		exportXls.setMargin(new java.awt.Insets(2, 5, 2, 5));
		exportXls.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				JxlExporter.exportXLS(table);
			}
		});

		chartGeneratorLabel.setBackground(new java.awt.Color(102, 102, 255));
		chartGeneratorLabel.setText("Generator");
		chartGeneratorLabel.setBorder(javax.swing.BorderFactory
				.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
		chartGeneratorLabel.setOpaque(true);
		chartGeneratorLabel.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				chartGeneratorLabelMouseClicked(evt);
			}
		});
		
		JButton btnAlignk = new JButton("Align 1/k0");
		btnAlignk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				alignK0ButtonActionPerformed();
			}
		});
		btnAlignk.setMargin(new Insets(2, 5, 2, 5));

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		layout.setHorizontalGroup(
			layout.createParallelGroup(Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
					.addContainerGap()
					.addComponent(showHeatmapButton)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(alignButton)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnAlignk)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(cacheImagesButton)
					.addPreferredGap(ComponentPlacement.RELATED, 76, Short.MAX_VALUE)
					.addComponent(chartGeneratorLabel)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(exportXls)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(saveAllButton)
					.addContainerGap())
				.addComponent(center, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				.addComponent(topPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
		);
		layout.setVerticalGroup(
			layout.createParallelGroup(Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
					.addGap(3)
					.addComponent(topPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGap(3)
					.addComponent(center, GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(layout.createParallelGroup(Alignment.BASELINE)
						.addComponent(showHeatmapButton)
						.addComponent(alignButton)
						.addComponent(saveAllButton)
						.addComponent(exportXls)
						.addComponent(chartGeneratorLabel)
						.addComponent(cacheImagesButton)
						.addComponent(btnAlignk)))
		);
		getContentPane().setLayout(layout);

		pack();
	}


	private void showHeatmapButtonActionPerformed(java.awt.event.ActionEvent evt) {
		showHeatmap();
	}

	private void cacheImagesButtonActionPerformed(java.awt.event.ActionEvent evt) {
		final int total = idataset.measurements.size();
		final Component parent = this;
		final WaitJDialog wait = new WaitJDialog("Caching data", total, parent);
		Runnable runnable = new Runnable() {

			public void run() {
				int i = 0;

				boolean abort = false;
				for (Measurement m : idataset.measurements) {
					String chachedFileName = new File(m.path).getName().replace(".csv", ".cca");
					if (!new File("ChartCache/" + chachedFileName).exists()) {
						Vector wrap = HEATMAP_BUFFER_IO.loadFromFile(new IMS_CSV_File(new File(m.path)), false);

						HEATMAP_BUFFER_IO.saveToCache(wrap, chachedFileName);
					} else {
						System.out.println(chachedFileName + " already cached");
					}

					abort = wait.tick(i, m.filename);
					if (abort) {
						break;
					}
					i++;

				} // for end

				wait.dispose();
				updateTable();
			}
		};
		Thread thread = new Thread(runnable);
		wait.setThread(thread);
		thread.start();
	}// GEN-LAST:event_cacheImagesButtonActionPerformed

	private void alignButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_alignButtonActionPerformed
		if (!getSelectedSubstance().name.equals("")) {
			AlignInternalFrame af = new AlignInternalFrame(this, getSelectedSubstance(), heatmapInternalFrame);
			BaseFrame.applyFrame(af);
		}

	}// GEN-LAST:event_alignButtonActionPerformed

	private void labelButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_labelButtonActionPerformed
		if (selectedLabel != -1) {
			table.getColumnModel().getColumn(selectedLabel).setCellRenderer(tcr);
		}
		if (selectedLabel == table.getSelectedColumn()) {
			table.getColumnModel().getColumn(selectedLabel).setCellRenderer(tcr);
			selectedLabel = -1;
		} else {
			ColorColumnRenderer ccr = new ColorColumnRenderer(new Color(200, 200, 255));
			selectedLabel = table.getSelectedColumn();
			table.getColumnModel().getColumn(selectedLabel).setCellRenderer(ccr);

			if (selectedClasses == selectedLabel) {
				selectedClasses = -1;
			}
		}
		repaint();
	}// GEN-LAST:event_labelButtonActionPerformed

	private void classesButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_classesButtonActionPerformed
		if (selectedClasses != -1) {
			table.getColumnModel().getColumn(selectedClasses).setCellRenderer(tcr);
		}
		if (selectedClasses == table.getSelectedColumn()) {
			table.getColumnModel().getColumn(selectedClasses).setCellRenderer(tcr);
			selectedClasses = -1;
		} else {
			ColorColumnRenderer ccr = new ColorColumnRenderer(new Color(255, 200, 200));
			selectedClasses = table.getSelectedColumn();
			table.getColumnModel().getColumn(selectedClasses).setCellRenderer(ccr);

			if (selectedClasses == selectedLabel) {
				selectedLabel = -1;
			}
		}
		repaint();
	}// GEN-LAST:event_classesButtonActionPerformed

	private void findPeaks(final boolean coarse) {
		final Vector<Measurement> selectedMeas = getSelectedMeasurements();
		final int total = selectedMeas.size();
		final Component parent = this;
		final WaitJDialog wait = new WaitJDialog("Detecting peaks (wst) ...", total, parent);
		Runnable runnable = new Runnable() {

			public void run() {
				int i = 0;

				boolean abort = false;
				for (Measurement m : selectedMeas) {

					abort = wait.tick(i, m.filename);
					if (abort) {
						break;
					}
					i++;
					IMS_CSV_File imsfile = new IMS_CSV_File(new File(m.path));
					Peaklist pl = ImageMethods.detectPeaksWithWST(coarse,
							new File(m.path).getName().replace("ims.csv", "iphex.pl"), m.measurementID,
							imsfile.getMap(), imsfile.getScaleK0Inv(), imsfile.getScaleRT());

					idataset.addPeakList(pl);
				}
				wait.dispose();
				updateTable();
			}
		};

		Thread thread = new Thread(runnable);
		wait.setThread(thread);
		thread.start();
	}

	private void deleteSelectedPeaklistsActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_deleteSelectedPeaklistsActionPerformed
		ido_historySave();
		Vector<Measurement> selectedMeas = getSelectedMeasurements();
		for (int i = 0; i < selectedMeas.size(); i++) {
			String key = selectedMeas.get(i).measurementID;
			if (idataset.peaklists.containsKey(key)) {
				idataset.peaklists.remove(key);
			}
		}
		updateTable();
	}// GEN-LAST:event_deleteSelectedPeaklistsActionPerformed

	private void deleteAreasMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_deleteAreasMenuItemActionPerformed
		ido_historySave();
		idataset.clearSubstanceIdentifikations();
		updateTableWithoutHeatmap();
	}// GEN-LAST:event_deleteAreasMenuItemActionPerformed

	private void exportSelectedPeaklistsActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_exportSelectedPeaklistsActionPerformed
		JFileChooser chooser = new JFileChooser(BaseFrame.getSelectedFileTreeFile());
		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		int returnVal = chooser.showOpenDialog(this);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			Vector<Measurement> selectedMeas = getSelectedMeasurements();
			for (int i = 0; i < selectedMeas.size(); i++) {
				String id = selectedMeas.get(i).measurementID;
				if (idataset.peaklists.containsKey(id)) {
					idataset.peaklists.get(id).writeToFolder(chooser.getSelectedFile());
				}
			}
		}
	}// GEN-LAST:event_exportSelectedPeaklistsActionPerformed

	private void saveAllButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_saveAllButtonActionPerformed
		JFileChooser chooser = new JFileChooser(BaseFrame.getSelectedFileTreeFile());
		chooser.setDialogType(JFileChooser.SAVE_DIALOG);
		int returnVal = chooser.showOpenDialog(this);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			File filename = chooser.getSelectedFile();
			if (!filename.toString().endsWith(".ido")) {
				filename = new File(filename + ".ido");
			}
			try {
				ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(filename));

				oo.writeObject(idataset);
				oo.close();

				// String test = idataset.ObjectToString();

				// File _file = new File(chooser.getSelectedFile()+".RS");

				// FileWriter writer = new FileWriter(_file);

				// writer.write(test);
				// writer.flush();
				// writer.close();

				System.out.println(filename + " saved.");
				// System.out.println(test);

			} catch (IOException ex) {
			}
		}
	}// GEN-LAST:event_saveAllButtonActionPerformed

	private void undoButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_undoButtonActionPerformed
		ObjectInputStream oi = null;
		try {
			oi = new ObjectInputStream(new FileInputStream(new File("undofile.undo")));
			iDataSet undoIDS = (iDataSet) oi.readObject();
			this.idataset = undoIDS;
			updateTable();
			oi.close();
			System.out.println("Valid UNDO object found, loading ..");
		} catch (Exception ex) {
			try {
				oi.close();
			} catch (Exception ex1) {
				System.out.println("Warning, can not close damaged object in stream ...");
			}
			System.out.println(ex.getMessage());
			System.out.println("Error loading UNDO object ..");
		}

	}// GEN-LAST:event_undoButtonActionPerformed

	private void showSampleTypeCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_showSampleTypeCheckBoxActionPerformed
		idataset.showSampleTypeInformation = showSampleTypeCheckBox.isSelected();
		updateTable();
	}// GEN-LAST:event_showSampleTypeCheckBoxActionPerformed

	private void copyAreasMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_copyAreasMenuItemActionPerformed
		Vector<String[]> v = new Vector<String[]>();

		for (SubstanceInfo s : idataset.substanceInfos) {
			v.add(s.getSubstanceParameter());
		}
		GeneralTabInternalFrame tif = new GeneralTabInternalFrame(v);
		BaseFrame.applyFrame(tif);
		tif.moveToFront();
		tif.setLocation(this.getLocation().x, this.getLocation().y);
	}// GEN-LAST:event_copyAreasMenuItemActionPerformed

	private void addToNewMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_addToNewMenuItemActionPerformed
		ido_historySave();
		String headerName = "";
		Vector<String> firstColumn = getColumnAt(table.getSelectedColumns()[0]);
		headerName += getHeaderNameAt(table.getSelectedColumns()[0]);

		for (int i = 1; i < table.getSelectedColumns().length; i++) {
			int j = table.getSelectedColumns()[i];
			headerName += getHeaderNameAt(j);
			if (i != table.getSelectedColumns().length - 1) {
				headerName += "+";
			}
			Vector<String> columnToAdd = getColumnAt(j);
			for (int k = 0; k < columnToAdd.size(); k++) {
				String first = firstColumn.elementAt(k);
				String toAdd = columnToAdd.elementAt(k);
				String result = (Double.parseDouble(first) + Double.parseDouble(toAdd) + "");
				firstColumn.set(k, result);
			}
		}
		Vector<String> MId = getColumnAt(1);
		Vector<IdInfo> idInfos = new Vector<IdInfo>();
		for (int i = 0; i < MId.size(); i++) {
			String mid = MId.elementAt(i);
			Vector<String> temp = new Vector<String>();
			temp.add(firstColumn.elementAt(i));
			idInfos.add(new IdInfo(mid, temp));
		}
		idataset.addMeasurementIdInfos(idInfos, new String[] { headerName });
		updateTable();
	}// GEN-LAST:event_addToNewMenuItemActionPerformed

	public Vector<String> getSelectedLabelColumn() {
		Vector<String> xAxisLabels = null;
		if (selectedLabel != -1) {
			xAxisLabels = new Vector<String>();
			for (int i = 0; i < table.getRowCount(); i++) {
				String value = (String) table.getValueAt(i, selectedLabel);
				xAxisLabels.add(value);
			}
		}
		return xAxisLabels;
	}

	public Vector<String> getSelectedClassColumn() {
		Vector<String> classes = null;
		if (selectedClasses != -1) {
			classes = new Vector<String>();
			for (int i = 0; i < table.getRowCount(); i++) {
				String value = (String) table.getValueAt(i, selectedClasses);
				classes.add(value);
			}
		}
		return classes;
	}

	public Vector<String> getColumnAt(int pos) {
		Vector<String> columndata = new Vector<String>();
		for (int i = 0; i < table.getRowCount(); i++) {
			String value = (String) table.getValueAt(i, pos);
			columndata.add(value);
		}
		return columndata;
	}

	public String getHeaderNameAt(int pos) {
		return table.getTableHeader().getColumnModel().getColumn(pos).getHeaderValue().toString();
	}

	public String getClassforMeasurement(Measurement m) {
		if (selectedClasses == -1) {
			return "";
		}
		for (int i = 0; i < table.getRowCount(); i++) {
			if (table.getValueAt(i, 1).toString().equals(m.measurementID)) {
				return table.getValueAt(i, selectedClasses).toString();
			}

		}
		return "";
	}

	public Vector<Double> getColumnForSubstance(String substancename) {
		int pos = -1;
		for (int i = 0; i < table.getColumnCount(); i++) {
			String head = table.getTableHeader().getColumnModel().getColumn(i).getHeaderValue().toString();
			// if(head.contains("<HTML>")){
			// head = head.replace("<HTML>","Area (").replace("-<br>","-").replace("</HTML>",")");
			// }
			if (head.equals(substancename)) {
				pos = i;
				break;
			}
		}
		Vector<String> sv = getColumnAt(pos);
		Vector<Double> dv = new Vector<Double>();
		for (int i = 0; i < sv.size(); i++) {
			String string = sv.elementAt(i);
			dv.add(Double.parseDouble(string));
		}
		return dv;
	}

	private void chartFromColumnMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_chartFromColumnMenuItemActionPerformed
		// if column 0 is selected, plot all series in one chart
		if (selectedClasses == 0) {
			Vector<String> classes = new Vector<String>();
			Vector<String> xAxisLabels = new Vector<String>();
			int nrOfSelectedColumns = table.getSelectedColumnCount();
			Vector<Double> data = new Vector<Double>();
			for (int j = 0; j < table.getRowCount(); j++) {

				for (int i = 0; i < nrOfSelectedColumns; i++) {
					int cindx = table.getSelectedColumns()[i];
					data.add(Double.parseDouble((String) table.getValueAt(j, cindx)));
					classes.add(getSubstanceAt(cindx).name);
					xAxisLabels.add(table.getValueAt(j, 0).toString());
				}

			}
			ChartInternalFrame cif1 = new ChartInternalFrame("", data, classes, xAxisLabels);
			cif1.setBounds(20, 20, 600, 400);
			BaseFrame.applyFrame(cif1);
			cif1.moveToFront();

		} else {

			Vector<String> xAxisLabels = getSelectedLabelColumn();
			Vector<String> classes = getSelectedClassColumn();

			int xshift = 0;
			int yshift = 0;
			for (int i = 0; i < table.getSelectedColumns().length; i++) {
				int cindx = table.getSelectedColumns()[i];
				Vector<Double> data = new Vector<Double>();
				for (int j = 0; j < table.getRowCount(); j++) {
					data.add(Double.parseDouble(((String) table.getValueAt(j, cindx)).replace(",", ".")));
				}

				ChartInternalFrame cif = new ChartInternalFrame(getSubstanceAt(cindx).name, data, classes, xAxisLabels);

				// if column 1 is selected as label use date axis
				if (selectedLabel == 1) {
					cif.showAsXYTimeBarChart();
				}
				cif.dsif = this;

				cif.setBounds(xshift += 20, yshift += 20, 600, 400);
				BaseFrame.applyFrame(cif);
				cif.moveToFront();
			}
		}
	}// GEN-LAST:event_chartFromColumnMenuItemActionPerformed

	private void correlationAVAMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_correlationAVAMenuItemActionPerformed
		Vector<Double[]> columnData = new Vector<Double[]>();
		String[] columnHeader = new String[table.getSelectedColumns().length];
		for (int i = 0; i < table.getSelectedColumns().length; i++) {
			int cindx = table.getSelectedColumns()[i];
			// Vector<Double> data = new Vector<Double>();
			Double[] data = new Double[table.getRowCount()];
			for (int j = 0; j < table.getRowCount(); j++) {
				data[j] = (Double.parseDouble(((String) table.getValueAt(j, cindx)).replace(",", ".")));
			}
			columnData.add(data);
			columnHeader[i] = (getSubstanceAt(cindx).name);
		}

		int elements = columnData.size() * columnData.size();
		double[][] posCorrData = new double[3][elements];
		double[][] negCorrData = new double[3][elements];

		int dindx = 0;
		for (int i = 0; i < columnData.size(); i++) {
			for (int j = 0; j < columnData.size(); j++) {
				Double corr = Statistics.getCorrelation(columnData.get(i), columnData.get(j));
				if (corr >= 0) {
					posCorrData[0][dindx] = i;
					posCorrData[1][dindx] = j;
					posCorrData[2][dindx] = corr;
				} else {
					negCorrData[0][dindx] = i;
					negCorrData[1][dindx] = j;
					negCorrData[2][dindx] = corr * -1;
				}
				dindx++;
			}
		}

		DefaultXYZDataset imsdds = new DefaultXYZDataset();

		imsdds.addSeries("negativ correlated", negCorrData);
		imsdds.addSeries("positiv correlated", posCorrData);

		CorrelationBubblePlot cif = new CorrelationBubblePlot(imsdds, columnHeader, this);
		cif.setBounds(0, 0, 600, 400);
		BaseFrame.applyFrame(cif);
		cif.moveToFront();
	}// GEN-LAST:event_correlationAVAMenuItemActionPerformed

	private void editAreasMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_editAreasMenuItemActionPerformed

		ido_historySave();
		Vector<String[]> v = new Vector<String[]>();

		for (SubstanceInfo s : idataset.substanceInfos) {
			v.add(s.getSubstanceParameter());
		}
		GeneralTabInternalFrame tif = new GeneralTabInternalFrame(v);
		BaseFrame.applyFrame(tif);
		tif.moveToFront();
		tif.setLocation(this.getLocation().x, this.getLocation().y);

		idataset.clearSubstanceIdentifikations();
		updateTable();
	}// GEN-LAST:event_editAreasMenuItemActionPerformed

	private void addInfoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_addInfoMenuItemActionPerformed
		infoLabelInternalFrame jif = new infoLabelInternalFrame(this);
		jif.setLocation(600, 400);
		BaseFrame.applyFrame(jif);
	}// GEN-LAST:event_addInfoMenuItemActionPerformed

	private void deleteSelectedInformationActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_deleteSelectedInformationActionPerformed
		ido_historySave();
		// Vector<Integer> deletedColumns = new Vector<Integer>();
		for (int j = table.getSelectedColumns().length - 1; j >= 0; j--) {
			int selectedColumn = table.getSelectedColumns()[j];

			int infoShift = idataset.infoShift;
			Vector<String> MIds = getColumnAt(1);

			for (int i = 0; i < table.getRowCount(); i++) {
				String MId = MIds.get(i);
				idataset.measurementInfos.get(MId).remove(selectedColumn - infoShift);
			}
			// deletedColumns.add(selectedColumn - infoShift);

			Vector<String> nH = new Vector<String>();
			for (int i = 0; i < idataset.idHeader.length; i++) {
				if (i != selectedColumn - infoShift) {
					nH.add(idataset.idHeader[i]);
				}
			}

			String[] newHeader = new String[idataset.idHeader.length - 1];
			nH.toArray(newHeader);
			idataset.idHeader = newHeader;
			idataset.numberOfMeasurementInfos = newHeader.length;

		}
		updateTable();
	}// GEN-LAST:event_deleteSelectedInformationActionPerformed

	private void copyFilesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_copyFilesMenuItemActionPerformed
		JFileChooser chooser = new JFileChooser(BaseFrame.getSelectedFileTreeFile());
		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		int returnVal = chooser.showOpenDialog(this);
		chooser.setDialogType(JFileChooser.SAVE_DIALOG);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			File folder = chooser.getSelectedFile();
			for (Measurement m : idataset.measurements) {
				System.out.println(m.filename + " -> " + folder.getPath());
				Misc.copy(m.path, folder.getPath() + "/" + m.filename);
			}
		}

	}// GEN-LAST:event_copyFilesMenuItemActionPerformed

	private void chartGeneratorLabelMouseClicked(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_chartGeneratorLabelMouseClicked
		JLabel temp = chartGeneratorLabel;
		generatorPopup.show(temp, 0, temp.getHeight());
	}// GEN-LAST:event_chartGeneratorLabelMouseClicked

	private void saveChartsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_saveChartsMenuItemActionPerformed
		ChartExportOptionsInternalFrame ceif = new ChartExportOptionsInternalFrame(this);
		BaseFrame.applyFrame(ceif);
		ceif.setLocation(this.getLocation());
		ceif.moveToFront();
		ceif.show();
	}// GEN-LAST:event_saveChartsMenuItemActionPerformed

	private void WallpaperMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_WallpaperMenuItemActionPerformed
		WallpaperInternalFrame wif = new WallpaperInternalFrame(this);
	}// GEN-LAST:event_WallpaperMenuItemActionPerformed

	private void pcaActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_pcaActionPerformed
		new PcaInternalFrame(this);
	}// GEN-LAST:event_pcaActionPerformed

	private void heatCellsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_heatCellsMenuItemActionPerformed
		updateTableWithoutHeatmap();
	}// GEN-LAST:event_heatCellsMenuItemActionPerformed

	private void multiplyToNewMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_multiplyToNewMenuItemActionPerformed
		ido_historySave();
		String headerName = "";
		Vector<String> firstColumn = getColumnAt(table.getSelectedColumns()[0]);
		headerName += getHeaderNameAt(table.getSelectedColumns()[0]);

		for (int i = 1; i < table.getSelectedColumns().length; i++) {
			int j = table.getSelectedColumns()[i];
			headerName += getHeaderNameAt(j);
			if (i != table.getSelectedColumns().length - 1) {
				headerName += "*";
			}

			Vector<String> columnToAdd = getColumnAt(j);
			for (int k = 0; k < columnToAdd.size(); k++) {
				String first = firstColumn.elementAt(k);
				String toAdd = columnToAdd.elementAt(k);
				String result = (Double.parseDouble(first.replace(",", "."))
						* Double.parseDouble(toAdd.replace(",", ".")) + "");
				firstColumn.set(k, result);
			}
		}
		Vector<String> MId = getColumnAt(1);
		Vector<IdInfo> idInfos = new Vector<IdInfo>();
		for (int i = 0; i < MId.size(); i++) {
			String mid = MId.elementAt(i);
			Vector<String> temp = new Vector<String>();
			temp.add(firstColumn.elementAt(i));
			idInfos.add(new IdInfo(mid, temp));
		}
		idataset.addMeasurementIdInfos(idInfos, new String[] { headerName });
		updateTable();
	}

	private void useRlActionPerformed(java.awt.event.ActionEvent evt) {
		int[] selectedRowsArray = table.getSelectedRows();
		int nrOfSelectedRows = selectedRowsArray.length;
		Vector<Integer> selectedRows = new Vector<Integer>(nrOfSelectedRows);
		for (int i = 0; i < nrOfSelectedRows; i++) {
			selectedRows.add(selectedRowsArray[i]);
		}
		final HashMap<String, Measurement> mhm = new HashMap<String, Measurement>();

		for (int i = 0; i < idataset.measurements.size(); i++) {
			mhm.put(idataset.measurements.get(i).measurementID, idataset.measurements.get(i));
		}

		ArrayList<Measurement> als = new ArrayList<Measurement>();
		ArrayList<Measurement> rls = new ArrayList<Measurement>();

		for (int i = 0; i < table.getRowCount(); i++) {
			Measurement m = mhm.get(table.getValueAt(i, 1).toString());
			if (selectedRows.contains(i)) {
				rls.add(m);
				idataset.measurements.remove(m);
			} else {
				als.add(m);
			}
		}
		int validTimeDistance = 60;
		Vector<IdInfo> idinfos = new Vector<IdInfo>();

		for (Measurement al : als) {
			String dateAL = al.measurementID.substring(0, 6);
			String hoursAL = al.measurementID.substring(6, 8);
			String minutesAL = al.measurementID.substring(8, 10);
			int totalMinutesAL = Integer.parseInt(hoursAL) * 60 + Integer.parseInt(minutesAL);

			Measurement closestRlMeasurement = null;
			int closestTimeIntervall = validTimeDistance;

			for (Measurement rl : rls) {
				String dateRL = rl.measurementID.substring(0, 6);
				if (dateAL.equals(dateRL)) {
					String hoursRL = rl.measurementID.substring(6, 8);
					String minutesRL = rl.measurementID.substring(8, 10);
					int totalMinutesRL = Integer.parseInt(hoursRL) * 60 + Integer.parseInt(minutesRL);
					int timeDistance = totalMinutesAL - totalMinutesRL;
					if (timeDistance < closestTimeIntervall && timeDistance > 0) {
						closestTimeIntervall = timeDistance;
						closestRlMeasurement = rl;
					}
				}
			}
			if (closestRlMeasurement != null) {
				Vector<String> stringInfos = new Vector<String>();
				stringInfos.add(closestTimeIntervall + "");
				stringInfos.add(closestRlMeasurement.filename);
				IdInfo idi = new IdInfo(al.measurementID, stringInfos);
				idinfos.add(idi);
				idataset.RLpeaklists.put(al.measurementID, idataset.peaklists.get(closestRlMeasurement.measurementID));
			} else {
				idataset.measurements.remove(al);
			}
		}
		idataset.addMeasurementIdInfos(idinfos, new String[] { "Minutes to Reference", "Reference" });
		idataset.autoSubtractRL = true;
		updateTableWithoutHeatmap();

	}

	private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {// GEN-FIRST:event_formInternalFrameClosing
		try {
			if (heatmapInternalFrame != null) {
				System.out.println("Found heatmap visualisatuion linked to datasource, closing it ...");
			}
			closeHeatmap();
		} catch (Exception ex) {
			System.out.println("Error during heatmap closing!");
		}
	}

	private javax.swing.JMenuItem WallpaperMenuItem;
	private javax.swing.JMenuItem addInfoMenuItem;
	private javax.swing.JMenuItem addToNewMenuItem;
	private javax.swing.JLabel areasLabel;
	private javax.swing.JPopupMenu areasPopup;
	public javax.swing.JPanel center;
	private javax.swing.JMenuItem chartFromColumnMenuItem;
	private javax.swing.JLabel chartGeneratorLabel;
	private javax.swing.JMenuItem clearInformationTable;
	private javax.swing.JMenuItem copyAreasMenuItem;
	private javax.swing.JMenuItem copyFilesMenuItem;
	private javax.swing.JMenuItem correlationAVAMenuItem;
	private javax.swing.JLabel dataLabel;
	private javax.swing.JPopupMenu dataPopup;
	private javax.swing.JMenuItem deleteAreasMenuItem;
	private javax.swing.JMenuItem deleteDataItem;
	private javax.swing.JMenuItem deleteSelectedInformation;
	private javax.swing.JMenuItem deleteSelectedPeaklists;
	private javax.swing.JMenuItem detectPeaksCoarseMenuItem;
	private javax.swing.JMenuItem detectPeaksFineMenuItem;
	private javax.swing.JMenuItem editAreasMenuItem;
	private javax.swing.JMenuItem exportSelectedPeaklists;
	private javax.swing.JMenu findPeaksMenu;
	private javax.swing.JPopupMenu generatorPopup;
	private javax.swing.JCheckBoxMenuItem heatCellsMenuItem;
	private javax.swing.JSeparator jSeparator1;
	private javax.swing.JSeparator jSeparator4;
	private javax.swing.JSeparator jSeparator5;
	private javax.swing.JSeparator jSeparator6;
	private javax.swing.JLabel metaInfoLabel;
	private javax.swing.JPopupMenu metaInfoPopup;
	private javax.swing.JMenuItem multiplyToNewMenuItem;
	private javax.swing.JMenuItem pca;
	private javax.swing.JLabel peakLabel;
	private javax.swing.JPopupMenu peakPopup;
	private javax.swing.JMenuItem saveChartsMenuItem;
	private javax.swing.JCheckBoxMenuItem showCommentCheckBox;
	private javax.swing.JCheckBoxMenuItem showAlignmentFactorCheckBox;
	private javax.swing.JCheckBoxMenuItem showDTCheckBox;
	private javax.swing.JCheckBoxMenuItem showFilenameCheckBox;
	private javax.swing.JToggleButton showHeatmapButton;
	private javax.swing.JCheckBoxMenuItem showMaxIntensityCheckBox;
	private javax.swing.JCheckBoxMenuItem showRTCheckBox;
	private javax.swing.JCheckBoxMenuItem showSampleTypeCheckBox;
	private javax.swing.JCheckBoxMenuItem showVolumeCheckBox;
	private javax.swing.JMenuItem useRl;

	private AlignK0InternalFrame alignK0InternalFrame;

	public void dragEnter(DropTargetDragEvent dtde) {
	}

	public void dragOver(DropTargetDragEvent dtde) {
	}

	public void dropActionChanged(DropTargetDragEvent dtde) {
	}

	public void dragExit(DropTargetEvent dte) {

		if (table.getSelectedColumn() != -1) {
			int clmnr = table.getSelectedColumn();
			StaticExchange.content = idataset.getHeader().get(clmnr);
		}
		if (selectedLabel != -1) {
			Vector<String> xAxisLabels = new Vector<String>();
			for (int i = 0; i < table.getSelectedRows().length; i++) {
				int selectedLine = table.getSelectedRows()[i];
				String value = (String) table.getValueAt(selectedLine, selectedLabel);
				xAxisLabels.add(value);
			}
			StaticExchange.xAxsisLabels = xAxisLabels;
		}
		if (selectedClasses != -1) {
			Vector<String> classes = new Vector<String>();
			for (int i = 0; i < table.getSelectedRows().length; i++) {

				int selectedLine = table.getSelectedRows()[i];
				String value = (String) table.getValueAt(selectedLine, selectedClasses);
				classes.add(value);
			}
			StaticExchange.classes = classes;
		}
	}

	public void drop(DropTargetDropEvent evt) {

		try {
			Transferable t = evt.getTransferable();
			String tabseparatedFileList = (String) t.getTransferData(DataFlavor.stringFlavor);
			addInformationFromDrop(tabseparatedFileList);
		} catch (UnsupportedFlavorException ex) {
		} catch (IOException ex) {
		}
	}

	
	/**
	 * 20.12.2011(Enable Rip position correction)
	 */
	protected void alignK0ButtonActionPerformed() {
		alignK0InternalFrame = new AlignK0InternalFrame(this);
		alignK0InternalFrame.setBounds(this.getBounds().x,this.getBounds().y,200,120);
		BaseFrame.applyFrame(alignK0InternalFrame);
	}
	
	/**
	 * 20.12.2011(Enable Rip position correction)
	 */
	public void setRipPositionsTo(double newRipPosition) {
		for (Peaklist pl : idataset.peaklists.values()){
			//if rip position was assigned during peak list generation
			if(pl.getOriginalRipPosition() != 0){
				double shift = newRipPosition - pl.getOriginalRipPosition();
				DecimalFormat f4 = new DecimalFormat("0.0000");
				double formatted = Double.parseDouble(f4.format(shift).replace(",","."));
				pl.shiftK0(formatted);
			}
		}
		
		BaseFrame.removeFrame(alignK0InternalFrame);
		updateTable();
		this.repaint();
	}
	/**
	 * 20.12.2011(Enable Rip position correction)
	 */
	public void resetRipPositions() {
		for (Peaklist pl : idataset.peaklists.values()){
			pl.resetK0Shift();
		}
		BaseFrame.removeFrame(alignK0InternalFrame);
		updateTable();
		this.repaint();
	}
}
